#!/usr/bin/env python3
# -*- coding: utf-8 -*-
'''
@File    :   show_battery.py
@Time    :   
@Author  :   YcZ
@Version :   v9.0.0_x3p_orin
@Contact :   zhouyuchao@neolix.cn
@License :   (C)Copyright 2021-2021, Neolix Technologies Co., Ltd.
'''


import re
import os
import time

def Battery():
    #   can1  200   [8]  0D 00 01 55 00 00 0C AA
    for line in os.popen('candump can1|grep 200'):
        time.sleep(0.2)
        h = re.split(' ', line)
        battery = int(h[12], 16)
        speed = (int(h[11], 16) & 0b11111000+int(h[10], 16) << 8)*0.05625
        battery_info = '电量: %3d%%' % battery
        speed_info = '车速: %3.3f m/s' % speed
        print('\r', battery_info, speed_info, '(Ctrl+C退出)', end='')

if __name__ == '__main__':
    Battery()
